package com.utils;

import java.nio.charset.StandardCharsets;

import org.apache.tomcat.util.codec.binary.Base64;

/**
 * @Author: zrhuang4
 * @CreateTime: 2023-03-15  21:56
 * @Description: TODO
 */

public class BasicAuth implements  Auth{
    private String username;

    private String password;

    public BasicAuth(String username, String password) {
        this.username = username;
        this.password = password;
    }

    @Override
    public String getAuth() {
        String auth = String.format("%s:%s", this.username, this.password);

        byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1));
        return "Basic " + new String(encodedAuth);
    }
}
